export class EventBus {
  messageList = {};

  subscribe(key, callback) {
    if (!this.messageList[key]) this.messageList[key] = [];
    this.messageList[key].push(callback);
  }

  publish(key, message) {
    if (!this.messageList[key]) return;
    for (const callback of this.messageList[key]) {
      callback.call(this, message);
    }
  }

  unsubscribe(key) {
    delete this.messageList[key];
  }
}
